﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FySystem.Extension
{
    public static class LongExtension
    {
        /// <summary>
        /// 将当前的数字作为时间戳，转换为日期格式
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(this long source)
        {
            try
            {
                DateTime dateTimeStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                //long lTime = long.Parse(source + "0000000");
                source = source * 10000000;
                TimeSpan toNow = new TimeSpan(source);

                return dateTimeStart.Add(toNow);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static long NVL(this long? source, long dest = 0)
        {
            return source == null ? dest : source.Value;
        }
    }
}
